﻿using UnityEngine;
using System.Collections;

public class facebookButton : MonoBehaviour {

	private void Awake()
	{
		FB.Init(SetInit, OnHideUnity);
	}
	
	private void SetInit()
	{
		enabled = true; // "enabled" is a property inherited from MonoBehaviour
	}
	
	private void OnHideUnity(bool isGameShown)
	{
		if (!isGameShown)
		{
			// pause the game - we will need to hide
			Time.timeScale = 0;
		}
		else
		{
			// start the game back up - we're getting focus again
			Time.timeScale = 1;
		}
	}
	// Use this for initialization
	void OnMouseDown()
	{
		if (FB.IsLoggedIn) {
			FB.Feed(
				link: "https://example.com/myapp/?storyID=thelarch",
				linkName: "Touch Or Die",
				linkCaption: "Touch or die, the game where you can die",
				linkDescription: "I did an amazing Score: "+Score.score+"!",
				picture: "http://bigbrowser.blog.lemonde.fr/files/2011/08/bowser1-530x507.jpg",
				callback: LogCallback
				);
				} 
		else {
						FB.Login ("public_profile", AuthCallback);
				}
	}
	void AuthCallback(FBResult result) {
		if(FB.IsLoggedIn) {
			Debug.Log(FB.UserId);
		} else {
			Debug.Log("User cancelled login");
		}
	}

	void LogCallback(FBResult response) {
		Debug.Log(response.Text);
	}
}
